package com.dongjiantong.app.controller.biz;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongjiantong.biz.model.DjtFarmReportsForms;
import com.dongjiantong.biz.service.DjtFarmReportsFormsService;
import com.dongjiantong.common.exceptions.HttpCode;
import com.dongjiantong.common.exceptions.OPServerException;
import com.dongjiantong.common.model.Response;
import com.dongjiantong.openplatform.annotations.OpenBean;
import com.dongjiantong.openplatform.annotations.OpenMethod;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMethod;


import java.util.Date;

/**
 * Created by ldf on 2017/11/20.
 */

@Slf4j
@OpenBean
public class DjtFarmReportsFormsController {
    @Reference(version = "1.0.0")
    private DjtFarmReportsFormsService djtFarmReportsFormsService;

    /**
     *  根据官方兽id和时间查询产地检疫报表
     *
     * @param pageNum   页码
     * @param pageSize  一页几条
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param vetUserId 官方兽医Id
     * @return
     */
    @OpenMethod(
            key = "app.DjtFarmReportsForms.selectByVetUserIdAndReportTime",
            paramNames = {"pageNum", "pageSize", "startTime","endTime","vetUserId"},
            httpMethods = RequestMethod.POST)
    public Response<PageInfo<DjtFarmReportsForms>> selectByVetUserIdAndReportTime(int pageNum, int pageSize, Date startTime, Date endTime, Long vetUserId) {

        if (vetUserId == null) {
            throw new OPServerException(HttpCode.BAD_REQUEST, "官方兽医ID为空");
        }
        try {

            PageInfo<DjtFarmReportsForms> pageInfo = djtFarmReportsFormsService.selectByVetUserIdAndReportTime(pageNum, pageSize, startTime, endTime, vetUserId);
            return Response.ok(pageInfo);
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new OPServerException(HttpCode.INTERNAL_SERVER_ERROR, "查询异常请稍后再试");
        }
    }




}
